import pandas as pd

def calculate_technical_indicators(df):
    # 计算RSI(14)
    delta = df['close'].diff()
    gain = delta.where(delta > 0, 0)
    loss = -delta.where(delta < 0, 0)
    avg_gain = gain.rolling(14).mean()
    avg_loss = loss.rolling(14).mean()
    rs = avg_gain / avg_loss
    df['rsi'] = 100 - (100 / (1 + rs))

    # 计算MACD
    ema12 = df['close'].ewm(span=12, adjust=False).mean()
    ema26 = df['close'].ewm(span=26, adjust=False).mean()
    df['macd'] = ema12 - ema26
    df['signal'] = df['macd'].ewm(span=9, adjust=False).mean()
    df['histogram'] = df['macd'] - df['signal']
    
    # 计算CCI(20)
    tp = (df['high'] + df['low'] + df['close']) / 3
    cci_mean = tp.rolling(20).mean()
    mad = tp.rolling(20).apply(lambda x: abs(x - x.mean()).mean())
    df['cci'] = (tp - cci_mean) / (0.015 * mad)
    
    # 计算BOLL(20)
    ma20 = df['close'].rolling(20).mean()
    std20 = df['close'].rolling(20).std()
    df['boll_upper'] = ma20 + 2 * std20
    df['boll_mid'] = ma20
    df['boll_lower'] = ma20 - 2 * std20
    
    return df.dropna()